var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WFNodeUserSettingWin.tsx
var WFNodeUserSettingWin_exports = {};
__export(WFNodeUserSettingWin_exports, {
  WFNodeUserSettingWin: () => WFNodeUserSettingWin
});
module.exports = __toCommonJS(WFNodeUserSettingWin_exports);
var import_icons = require("@ant-design/icons");
var import_react = require("react");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_util2 = require("./util");
var import_WFDynamicNodeUserWin = require("./WFDynamicNodeUserWin");
var columnProps = {
  sortable: false,
  resizable: false,
  columnSort: false
};
function WFNodeUserSettingWin(props) {
  const { nodeData, loginOrgInfo = {}, callBack, cancelBack } = props;
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const tableRef = (0, import_util.useApi)();
  const openWFDynamicNodeUserWin = (0, import_util.useRefCallback)(async (_nodeData) => {
    const radioItems = (0, import_util2.getUseDynamicType)(_nodeData.users.length > 0, _nodeData.assignAnyUsers);
    const WFDynamicNodeUserWin_callBack = (data) => {
      _nodeData.selectedData = data;
      _nodeData.dispVal = data.map((d) => d.userName).join();
      _nodeData.users = data;
      tableRef.current.getApi().refreshView();
    };
    await (0, import_util2.wfModal)({
      title: `${_nodeData.name}${import_util2.NGLang.taskHisNode}--${import_util2.NGLang.dynamicUsers}`,
      width: 900,
      footerLeft: /* @__PURE__ */ React.createElement(import_WFDynamicNodeUserWin.WFDynamicNodeUserWinFooter, { radioItems }),
      content: /* @__PURE__ */ React.createElement(
        import_WFDynamicNodeUserWin.WFDynamicNodeUserWin,
        {
          radioItems,
          selectedData: _nodeData.selectedData,
          loginInfo: loginOrgInfo,
          todoData: _nodeData.users,
          callBack: WFDynamicNodeUserWin_callBack
        }
      )
    });
  });
  const columns = (0, import_react.useMemo)(() => {
    const userStyle = { display: "flex", width: "100%", height: "100%", alignItems: "center", cursor: "pointer" };
    return [
      {
        ...columnProps,
        flex: 1,
        header: import_util2.NGLang.nodeId,
        dataIndex: "id"
      },
      {
        ...columnProps,
        flex: 1,
        header: import_util2.NGLang.nodeName,
        tooltip: true,
        dataIndex: "name"
      },
      {
        ...columnProps,
        flex: 3,
        header: import_util2.NGLang.user,
        dataIndex: "users",
        render: ({ value, rowIndex, table }) => {
          var _a;
          const row = table.getRow(rowIndex);
          return /* @__PURE__ */ React.createElement("div", { onClick: () => openWFDynamicNodeUserWin(row), style: userStyle }, /* @__PURE__ */ React.createElement("div", { className: "nowrap", style: { flex: 1 } }, (_a = row.selectedData) == null ? void 0 : _a.map((i) => i.userName).join(",")), /* @__PURE__ */ React.createElement(import_icons.FileSearchOutlined, { style: { color: "rgba(0, 0, 0, 0.25)" } }));
        }
      }
    ];
  }, []);
  const invokeOkHandler = (0, import_util.useRefCallback)(async () => {
    var _a, _b;
    if (!callBack) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.noCallBack);
      return;
    }
    const allRows = tableRef.current.getApi().getRows();
    const result = new Array();
    let isValid = true;
    for (let i = 0, len = allRows.length; i < len; i++) {
      if ((_a = allRows[i].selectedData) == null ? void 0 : _a.length) {
        result.push({ nodeId: allRows[i].id, userNos: allRows[i].selectedData.map((d) => d.userNo) });
      } else {
        isValid = false;
        break;
      }
    }
    if (isValid) {
      callBack(result);
      (_b = mCtx.ins) == null ? void 0 : _b.destroy();
      return;
    }
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.notAllNodeSetUser);
  });
  const invokeCancelHandler = (0, import_util.useRefCallback)(async () => {
    var _a;
    await (cancelBack == null ? void 0 : cancelBack());
    (_a = mCtx.ins) == null ? void 0 : _a.destroy();
  });
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler,
      invokeCancelHandler
    });
  }, []);
  return /* @__PURE__ */ React.createElement(import_util.Layout, { style: { height: 300, padding: 5 } }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_functionalComponent.Table, { bordered: true, headerHeight: 32, rowHeight: 30, ref: tableRef, columns, dataSource: nodeData })));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WFNodeUserSettingWin
});
